package com.qfedu.item.controller;

import com.github.pagehelper.PageInfo;
import com.qfedu.item.domain.Card;
import com.qfedu.item.response.Response;
import com.qfedu.item.service.intf.CardService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("card")
@RequiredArgsConstructor
public class CardController {

    private  final CardService service;


    @PostMapping("add")
    public Response<Card> save(@RequestBody Card card){
        service.addCard(card);
        return Response.success();
    }

    @GetMapping("page")
    public Response<PageInfo<Card>> viewCardByPage(Integer pageIndex, Integer pageSize) {
        return Response.success(service.selectCardByPage(pageIndex, pageSize));
    }

    @GetMapping("view/{id}")
    public Response<Card>viewCardById(@PathVariable("id") Integer id){
        return Response.success(service.selectById(id));
    }

    @GetMapping("like")
    public Response<PageInfo<Card>> viewCardByPageWithIds(Integer pageIndex, Integer pageSize, String ids) {
        return Response.success(service.selectByIds(pageIndex, pageSize, ids));
    }
}
